Basic Verilog Module Structure
A Verilog module is the fundamental building block for digital circuit design. The typical structure is:
module ModuleName(params); // Parameters usually include inputs and outputs
// Port Declarations
input [3:0] A, B; // 4-bit inputs
input C_in; // Single-bit input
output [3:0] Sum; // 4-bit output
output C_out; // Single-bit output
// Note: If parameters have different widths, declare them on separate lines.
// Internal Signal Declarations
wire C_0, C_1, C_2; // Wires connect components within the module
// Main Logic Design
FA FA1 (
.A(A[0]),
.B(B[0]),
.C_in(C_in),
.Sum(Sum[0]),
.C_out(C_0) // Corrected naming to C_out
);
endmodule
Key Points
module...endmodule: Defines the design block.- Ports (
input,output): Specify external connections. wire: Represents internal connections between components.- Instantiation: Using other modules (e.g.,
FAfor Full Adder) inside the main module.
Circuit Design Abstraction Levels in Verilog
There are four primary abstraction levels for designing digital circuits:
1. Gate Level
- Designs are described using individual logic gates (AND, OR, NOT, etc.).
- Example:
and (Y, A, B);
```
2. Data Flow Level
- Uses Boolean expressions or continuous assignments (
assign) to describe data movement. - Example:
assign Y = (A & B) | (~A & C);
```
3. Behavioural Level
- Describes circuit behaviour using high-level constructs like
if-else,case, and loops. - Example:
always @(*) begin
if (A > B)
Y = 1;
else
Y = 0;
end
```
4. Register-Transfer Level (RTL)
- Combines data flow and behavioural modelling.
- Focuses on data transfer between registers and operations performed on that data.
- Example:
always @(posedge clk) begin
Q <= D;
end
```